/**
 * 权限模块
 */
import React from 'react';
import { connect, Redirect } from 'umi';
import RenderAuthorized from '@/components/basicComp/Authorized';
import { fromJS, Map, is, List } from 'immutable';
import { Spin } from 'antd';

@connect(({ user }) => ({
  authority: user.authority,
  userId: user.user.userId,
}))
export default class index extends React.Component {
  async componentDidMount() {}
  shouldComponentUpdate(nextProps, nextState) {
    //优化代码
    return (
      !is(fromJS(this.props), fromJS(nextProps)) ||
      !is(fromJS(this.state), fromJS(nextState))
    );
  }
  render() {
    const Authorized = RenderAuthorized(this.props.authority); //设置路由权限  RenderAuthorized: (currentAuthority: string | () => string) => Authorized
    return (
      <React.Fragment>
        {this.props.userId && (
          <Authorized
            authority={this.props.route.authority}
            noMatch={
              <Redirect
                to={{
                  pathname: '/userLogin/login',
                }}
              />
            }
          >
            {this.props.children}
          </Authorized>
        )}
      </React.Fragment>
    );
  }
}
